from datetime import datetime
from flask import jsonify, Blueprint
from multiprocessing import Process
from env import logger
import logic

oj = Blueprint('oj', __name__)


# def process_decorator(func):
#     def wrapper():
#         p = Process(target=func)
#         p.start()
#         p.join()
#
#     return wrapper
# def test(func):
#     p = Process(target=func)
#     p.start()
#     p.join()

def ok():
    return jsonify({"Code": "200", "Msg": ""})
def response_ok(msg):
    return jsonify({"Code": "200", "Msg": msg})
def response_error(code, msg):
    return jsonify({"Code": code, "Msg": msg})


@oj.route("/<string:oj_name>/race/refresh", methods=['GET'])
def web_race(oj_name):
    match oj_name:
        case "cf":
            p = Process(target=logic.get_cf_race)
            p.start()
            p.join()
        case "at":
            p = Process(target=logic.get_at_race)
            p.start()
            p.join()
        case "nk":
            p = Process(target=logic.get_nk_race)
            p.start()
            p.join()
        case "lg":
            p = Process(target=logic.get_lg_race)
            p.start()
            p.join()
        case "acm":
            p = Process(target=logic.get_acm_race)
            p.start()
            p.join()
    return response_ok("refresh successful")


@oj.route("/", methods=['GET'])
def ping():
    return jsonify({"status": "ok"})
